<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="file" id="file1" />
    <button id="btnUpload">上传文件</button>
    <script src="./lib/jquery.js"></script>
    <script>
        $(function() {
            var btn = $('#btnUpload');
            btn.click(function() {
                var file = $('#file1').get(0).files[0]
                if (!file) {
                    alert('ddddd')
                    return
                }
                var fd = new FormData()
                fd.append('avatar', file)
                $.ajax({
                    type: 'POST',
                    url: 'http://www.liulongbin.top:3006/api/upload/avatar',
                    data: fd,
                    processData: false,
                    contentType: false,
                    success: function(res) {
                        console.log(res)
                    }
                })
            })
        })
    </script>
</body>

</html>